# -*- coding: utf-8 -*-

import logging 
#--- init logging
#format='%(module)s %(lineno)d %(asctime)s %(levelname)-8s %(message)s'

level=logging.INFO
logging.basicConfig(level=level,
                    format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
                    datefmt='%m-%d %H:%M',
                    filename='.log',
                    filemode='w')
# define a Handler which writes INFO messages or higher to the sys.stderr
_console = logging.StreamHandler()
_console.setLevel(level)
# set a format which is simpler for console use
_formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
# tell the handler to use this format
_console.setFormatter(_formatter)
# add the handler to the root logger
#logging.getLogger('').addHandler(_console)



#--- api
def getLog(name=''):
    """
    log(str name) -> logging
    
    如果用默认参数，即name==''，返回root logging
    其他name则返回相应名称的logging
    """
    return logging.getLogger(name)

log = getLog('default')


if __name__=='__main__':
    getLog().debug('hi log')
    getLog('chen').info('hi')
    getLog('chen').debug('??')
    getLog('chen').exception('exception ')